package cn.com.shaom.learning.sb.data.transactional.service;

import cn.com.shaom.learning.sb.data.transactional.User;
import cn.com.shaom.learning.sb.data.transactional.dao.UserRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * ClassName: UserServiceImpl
 * Description:
 * Date: 2017/12/26 15:32 【需求编号】
 *
 * @author Shaom
 * @version V1.0.0
 */
@Service
public class UserServiceImpl implements IUserService {


    @Resource
    private UserRepository userRepository;


    @Transactional
    @Override
    public void save(User user) {
        try {
            User u = userRepository.save(user);// 入库

            int i = 1 / 0;
        } catch (Exception e) {

        }

        User user2 = new User("Sam", "123");// 入库
        userRepository.save(user2);
    }

    @Transactional(noRollbackFor = Exception.class)
    @Override
    public void saveNotRollBack(User user) {
        userRepository.save(user); // 入库
        int i = 1 / 0;

        User user2 = new User("Sam", "123");
        userRepository.save(user2);// 没入库
    }
}
